#ifndef HTTPCONNECTION_H
#define HTTPCONNECTION_H

#include <boost/beast/http.hpp>
#include <boost/beast.hpp>
#include <boost/asio.hpp>
#include <memory>
#include <unordered_map>
//#include "../include/LogicHandler.h"
class LogicHandler;
namespace http=boost::beast::http;


class httpConnection:public std::enable_shared_from_this<httpConnection>{
public:
    httpConnection(boost::asio::io_context &_io_context);
    void start_read();
    ~httpConnection();
    boost::asio::ip::tcp::socket &get_socket(){
        return _socket;
    }
private:
    //每一个连接对应的socket

    friend class LogicHandler;
    void handle_request(const std::shared_ptr<httpConnection>&);
    boost::asio::ip::tcp::socket _socket;
    boost::beast::flat_buffer  _buffer{8192};  //用来作为接收数据的缓冲区，方便后续进行解析填充_request
    http::request<http::dynamic_body> _request; //请求头与请求体都在
    http::response<http::dynamic_body> _response;   //包头与包体

    //url解码
    void prase_get_url();
    std::unordered_map<std::string,std::string> url_key_value;  //url里查询参数url的键值对
    std::string _get_url;        //url前方路径  如get_test?sad=sad中的   get_test

    void response_404();
};


#endif